import dayjs from 'dayjs'
import { Button } from 'antd'
import { useState } from 'react'
import { useMount } from 'ahooks'

import { WijmoBase } from '../../Router/Wijmo'
import { GetIndexedDB } from '../../Utils/IndexedDB'
import { RedoOutlined, SearchOutlined, ExportOutlined } from '@ant-design/icons';


const wijmoConfig = async () => {
    const options = await GetIndexedDB('options')
    return ({
        get: 'getWebHuiZong',
        params: {
            statisticstype: 0,
            orgtype: 1,
            selecttype: 11,
            pageIndex: 1,
            pageSize: 100000,
        },
        initParameter: {
            group: [],
            sort: [],
            groupPanel: true,
            filter: true,
            addSum: true,
            addIndex: true,
            topText: 'Ω',
            btmText: 'Ψ',
        },
        configuration: {
            allowSorting: 'MultiColumn',
            isReadOnly: true,
            selectionMode: 5,
            allowMerging: "Cells",
        },
        optionsBtn: click => ([
            {
                key: '0',
                type: 'group',
                label: '数据',
                children: [
                    { key: 'refresh', label: <Button type='link' onClick={() => click('onRefresh')} ><RedoOutlined style={{ color: '#13c2c2' }} />刷新数据</Button> },
                    { key: 'search', label: <Button type='link' onClick={() => click('onSearch')} ><SearchOutlined style={{ color: '#13c2c2' }} />条件搜索</Button> },
                ],
            },
            {
                key: '2',
                type: 'group',
                label: '导出',
                children: [
                    { key: '2-1', label: <Button type='link' onClick={() => click('onSaveAct')}><ExportOutlined style={{ color: '#13c2c2' }} />导出选中数据</Button> },
                    { key: '2-2', label: <Button type='link' onClick={() => click('onSaveAll')}><ExportOutlined style={{ color: '#13c2c2' }} />导出全部数据</Button> },
                    { key: '2-3', label: <Button type='link' onClick={() => click('onSaveAdm', { url: 'getFeiYongExcel', search: true })}><ExportOutlined style={{ color: '#13c2c2' }} />导出模板数据</Button> },
                ],
            },
        ]),

        columns: [ // 字段设置
            {
                dataIndex: 'rid',
                valueType: 'Hidden'
            },

            {
                title: '材料名称',
                dataIndex: 'yS_CaiLiaoName',
                valueType: 'Input',
                width: '1*',
                align: 'center'
            },
            {
                title: '组织机构',
                dataIndex: 'pguid',
                valueType: 'Select',
                width: '1*',
                align: 'center',
                valueEnum: options.orgInfo,
                initialValue: options.orgInfo[0].uuid,
                fieldNames: { value: "uuid" },
                hideInTable: true
            },
            {
                title: '收料开始时间',
                dataIndex: 'begindate',
                valueType: 'DatePicker',
                picker: 'date',
                initialValue: dayjs().add(-2, 'day').format('YYYY-MM-DD'),
                hideInTable: true,
            },
            {
                title: '收料结束时间',
                dataIndex: 'enddate',
                valueType: 'DatePicker',
                picker: 'date',
                initialValue: dayjs().format('YYYY-MM-DD'),
                hideInTable: true,
            },

            {
                title: '总金额',
                dataIndex: 'totalMoney',
                valueType: 'Input',
                width: '1*',
                align: 'center',
                format: 'n2',
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计',
                hideInSearch: true,
            },
            {
                title: '已对账',
                dataIndex: 'settleMoney',
                valueType: 'Input',
                width: '1*',
                align: 'center',
                format: 'n2',
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计',
                hideInSearch: true,
            },
            {
                title: '未对账',
                dataIndex: 'outstandingMoney',
                valueType: 'Input',
                width: '1*',
                align: 'center',
                format: 'n2',
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计',
                hideInSearch: true,
            },
        ],
    })
}



const CaiLiaoFei = () => {
    const [WijmoConfig, setWijmoConfig] = useState()
    useMount(async () => setWijmoConfig(await wijmoConfig()))
    return (
        <div className='CaiLiaoFei'>
            {WijmoConfig && <WijmoBase Config={WijmoConfig} />}
        </div>
    )
};

export default CaiLiaoFei;